package org.liang.activemq.mq;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.liang.activemq.config.constant.ActiveMqConstant;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.listener.adapter.MessageListenerAdapter;
import org.springframework.stereotype.Component;

/**
 * 
 * activeMq消息消费端配置
 * @author liang
 * @date 2018年1月25日 下午2:17:06
 * @version 1.0
 */
@Component("activeMqTestReceiver")  
public class ActiveMqTestReceiver extends MessageListenerAdapter{  
      
	/**
	 * 注解方式监听mq消息
	 */
	@JmsListener(destination=ActiveMqConstant.MQ_SUBJECT_TEST1,concurrency="5-10")
	public void onMessage(Message message, Session session) throws JMSException {
		String msg="";
		try {
			msg =message.toString();
//			msg = (String) getMessageConverter().fromMessage(message);
			System.out.println("mq接收消息：" + msg);
			 //数据不为空则更新
		} catch (Exception e) {
			System.out.println("activeMq接收消息失败;消息:" +msg);
			e.printStackTrace();
		}
	}  
}  